package com.example.eventmechanism;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends Activity implements View.OnClickListener {

    //用于显示哪个按钮被点击
    TextView show;

    Button bn1, bn2, bn3, bn4, bn5;
    @BindView(R.id.button6)
    Button button6;
    @BindView(R.id.button7)
    Button button7;
    @BindView(R.id.button8)
    Button button8;

    @Override
    protected void onCreate(Bundle saveInstanceState) {
        super.onCreate(saveInstanceState);
        setContentView(R.layout.activity_main);

        show = (TextView) findViewById((R.id.text1));

        bn1 = (Button) findViewById(R.id.button1);
        bn2 = (Button) findViewById(R.id.button2);
        bn3 = (Button) findViewById(R.id.button3);
        bn4 = (Button) findViewById(R.id.button4);
        bn5 = (Button) findViewById(R.id.button5);

        //使用Activity作为监听器
        bn1.setOnClickListener(this);

        //使用匿名内部类作为监听器
        bn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                show.setText("点击采用了匿名内部类为监听器");
            }
        });

        //调用内部类监听器
        bn4.setOnClickListener(new MyClickListener());

        //调用外部类监听器
        bn5.setOnClickListener(new Outside(show));

        //ButterKnife
        ButterKnife.bind(this);
    }

    //使用Activity作为监听器
    @Override
    public void onClick(View v) {
        show.setText("点击采用了Activity为监听器");
    }

    //使用绑定到标签的监听器
    public void clickHandler(View Source) {
        show.setText("点击采用了绑定到标签的监听器");
    }

    //使用内部类作为监听器
    class MyClickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            show.setText("点击采用了内部类为监听器");
        }
    }

    //使用ButterKnife绑定的监听器
    @OnClick({R.id.button6, R.id.button7, R.id.button8})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.button6:
                show.setText("点击采用了ButterKnife绑定的监听器");
                break;
            case R.id.button7:
                Intent intent=new Intent(this,InformationActivity.class);
                startActivity(intent);//跳转到显示信息的活动
                break;
            case R.id.button8:
                Intent intent2=new Intent(this,ProgressActivity.class);
                startActivity(intent2);//跳转到显示进度对话框的活动
                break;
        }
    }
}
